<?php

namespace App\Http\Controllers\Web\Buyer;

use App\ConstDir\ErrorConst;
use App\Http\Controllers\Web\BaseController;
use App\Repository\Repositories\Interfaces\UserContractsRepository;
use Illuminate\Support\Facades\Cache;
use Illuminate\Http\Request;

/**
 * 买家合同信息API控制器
 *
 * @package App\Http\Controllers\Web\Buyer
 */
class UserContractsController extends BaseController
{
	/**
	 * @var UserContractsRepository
	 */
	protected $user_contracts_repo;

	public function __construct(UserContractsRepository $user_contracts_repo,Request $request)
	{
		parent::__construct();

		$this->user_id = array_get($this->user, 'id');

		$this->user_contracts_repo = $user_contracts_repo;
        $order_id = route_parameter('order_id', 0);

        if(!$order_id){
            return $this->error(ErrorConst::ERROR_CODE_MSG, ErrorConst::ERROR_CODE);
        }

        $this->user_contracts_repo->scopeQuery(function ($query) use($order_id){
            return $query->where(['order_id'=>$order_id,'user_id'=>$this->user_id]);
        });
	}

	public function index(Request $request)
	{
		$user_contracts = $this->user_contracts_repo->all();
		return $this->success(ErrorConst::SUCCESS_CODE, $user_contracts['data'],true);

	}

	public function show($id)
	{
		// $contracts = $this->user_contracts_repo->find($id);
		// return $this->success(ErrorConst::SUCCESS_CODE_MSG, $contracts['data']);
	}

	public function store()
	{

	}

	public function update(Request $request)
	{

	}

	public function delete($id)
	{

	}

}
